package com.ferry.transport.netty.lb;

import com.ferry.transport.api.Directory;
import com.ferry.transport.api.channel.WrappedChannelGroup;

import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Created by daiyong
 */
public class RoundRobinLoadBalancer implements LoadBalancer {

	private final static AtomicLong next = new AtomicLong(0);

	@Override
	public WrappedChannelGroup select(CopyOnWriteArrayList<WrappedChannelGroup> groupList) {
		Long nextIndex = next.getAndIncrement() % groupList.size();
		return groupList.get(nextIndex.intValue());
	}
}
